package com.example.delicioushunter.view.adapter;

import java.util.ArrayList;

import com.example.delicioushunter.R;
import com.example.delicioushunter.model.object.Material;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MaterialAdapter extends ArrayAdapter<Material> {
	private ArrayList<Material> materials;
	private Context mContext;

	public MaterialAdapter(Context context, ArrayList<Material> materials) {
		super(context, R.layout.row_material, materials);
		this.mContext = context;
		this.materials = materials;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.row_material, parent, false);
		RelativeLayout layoutMaterial = (RelativeLayout) rowView.findViewById(R.id.layoutMaterial);
		ImageView imgMaterial = (ImageView) rowView.findViewById(R.id.imgMaterial);
		TextView txtMaterialName = (TextView) rowView.findViewById(R.id.txtMaterialName);

		Material m = materials.get(position);
		txtMaterialName.setText(" "+m.getName()+" ");
		imgMaterial.setImageBitmap(m.getImage());
		return rowView;
	}
}
